// app.js
App({
  onLaunch: function () {
    if (!wx.cloud) {
      console.error('请使用 2.2.3 或以上的基础库以使用云能力');
    } else {
      wx.cloud.init({
         env: 'cloud1-7ge3r2d44d1ee4ba',
        traceUser: true,
      });

      wx.cloud.callFunction({
        name: 'login'
      }).then((res) => {
       console.log(res)
       wx.setStorageSync('openid', res.result.openid)
        wx.cloud.database().collection('users').where({
          zhanghao:wx.getStorageSync('user').zhanghao||'',
          mima:wx.getStorageSync('user').mima||'',
        }
          ).get().then(res=>{
            console.log(res);
          if(res.data.length>0&&res.data[0].type==='已审核'){
           wx.setStorageSync('user', res.data[0])
            wx.hideLoading({
              success: (res) => {},
            })
            if(res.data[0].xinwentype == '医院')
            {
              wx.navigateTo({
                url: '../newyiyuan/index',
              })
            }
            
            else {
            
              wx.reLaunch({
                url: '../index/index',
              })
            }

          }

          else if((res.data.length>0&&res.data[0].type==='待审核')){
            wx.reLaunch({
              url: '/pages/daishenhe/index',
            })
          }

          else {
              wx.hideLoading({
              success: (res) => {},
            })
            wx.reLaunch({
              url: '/pages/shouye/index',
            })
          }
        })
    } 
  )

}
    this.globalData = {};
    this.userInfo={}
  }
});
